package com.yc.game.cms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yc.game.cms.dao.UserMapper;
import com.yc.game.cms.pojo.User;
import com.yc.game.cms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    /**
     * 查询所有用户
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<User> getAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<User> userList = userMapper.getAll();
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        return pageInfo;
    }

    /**
     * 更新用户信息
     * @param user
     * @return
     */
    @Override
    public int updateUserInfo(User user) {
        User newUser = new User();
        newUser.setId(user.getId());
        newUser.setStatus(user.getStatus());
        newUser.setType(user.getType());
        return userMapper.updateByPrimaryKeySelective(newUser);
    }

    /**
     * 根据用户主键删除用户
     * @param userId
     * @return
     */
    @Override
    public int deleteById(Integer userId) {
        return userMapper.deleteByPrimaryKey(userId);
    }
}
